package com.bj.controller;

import com.bj.domain.Student;
import com.bj.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shkstart
 * @create 2021-09-06 23:13
 */
@Controller
@RequestMapping("/student")
public class StudentController {
    @Resource
    private StudentService service;
    //注册学生
    @RequestMapping("/addStudent.do")
    public ModelAndView addStudent(Student student){
        ModelAndView mv=new ModelAndView();
        String tips;
        int nums=service.addStudent(student);
        if(nums>0){
            tips="学生{"+student.getName()+"}注册成功";
        }else{
            tips="注册失败";
        }
        mv.addObject("tips",tips);
        mv.setViewName("result");
        return mv;

    }

    //处理查询
    @RequestMapping("/queryStudent.do")
    @ResponseBody
    public List<Student> queryStudent(){
        List<Student> students = service.findStudents();
        return students;
    }
}
